﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <el-form ref="formRefProductionLine" :model="stateProductionLine.vmModel" label-width="100px">
    <div style="margin-bottom:10px;">{{$t('message.autotrans.SysBatchEditConfirm')}}</div>
    <el-row>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Name_FormItem" prop="LinkedVM.Name" :label="$t('message.autotrans._Model_ProductionLine_Name')"          :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_ProductionLine_Name')}), trigger: 'blur' }]" >
          <el-input v-model="stateProductionLine.vmModel.LinkedVM.Name" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Code_FormItem" prop="LinkedVM.Code" :label="$t('message.autotrans._Model_ProductionLine_Code')"          :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_ProductionLine_Code')}), trigger: 'blur' }]" >
          <el-input v-model="stateProductionLine.vmModel.LinkedVM.Code" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_ProductName_FormItem" prop="LinkedVM.ProductName" :label="$t('message.autotrans._Model_ProductionLine_ProductName')">
          <el-input v-model="stateProductionLine.vmModel.LinkedVM.ProductName" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_PrincipalIdId_FormItem" prop="LinkedVM.PrincipalIdId" :label="$t('message.autotrans._Model_ProductionLine_PrincipalId')">
          <el-select v-model="stateProductionLine.vmModel.LinkedVM.PrincipalIdId" clearable>
             <el-option v-for="item in stateProductionLine.AllPrincipalIds" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
          </el-select>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Active_FormItem" prop="LinkedVM.Active" :label="$t('message.autotrans._Model_ProductionLine_Active')">
          <el-select v-model="stateProductionLine.vmModel.LinkedVM.Active" clearable>
             <el-option :key="1" :value=true :label="$t('message._system.common.vm.tips_bool_true')"></el-option>
             <el-option :key="0" :value=false :label="$t('message._system.common.vm.tips_bool_false')"></el-option>
          </el-select>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Aux_1_FormItem" prop="LinkedVM.Aux_1" :label="$t('message.autotrans._Model_ProductionLine_Aux_1')">
          <el-input v-model="stateProductionLine.vmModel.LinkedVM.Aux_1" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Aux_2_FormItem" prop="LinkedVM.Aux_2" :label="$t('message.autotrans._Model_ProductionLine_Aux_2')">
          <el-input v-model="stateProductionLine.vmModel.LinkedVM.Aux_2" clearable></el-input>
      </el-form-item>

      </el-col>
    </el-row>

    <div style="text-align:right;">
      <WtmButton @click="onSubmitProductionLine"  type="primary" :button-text="$t('message.autotrans.SysSubmit')" style="margin-top:15px;"/>

      <WtmButton @click="onCloseProductionLine"  type="primary" :button-text="$t('message.autotrans.SysClose')" style="margin-top:15px;"/>

    </div>

  </el-form>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageFactoryManagementProductionLineBatchEdit;false">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { productionlineApi } from '/@/api/factorymanagement/productionline';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;


// 定义变量内容
const formRefProductionLine = ref();
const stateProductionLine = reactive({
    vmModel: {
	  LinkedVM:{
        Name: '',
        Code: '',
        ProductName: '',
        PrincipalIdId: null,
        Active: undefined,
        Aux_1: '',
        Aux_2: '',
      },
      Ids:[],
      
	},
    
    AllPrincipalIds: [] as any[],
});

// 取消
const onCloseProductionLine = () => {
    closeDialog();
};

// 提交
const onSubmitProductionLine = () => {
	const loadingInstance = ElLoading.service({
		lock: true,
		text: '正在提交中，请等待。。。',
		background: 'rgba(0, 0, 0, 0.7)',
	});

    formRefProductionLine.value?.validate((valid: boolean, fields: any) => {
		if (valid) {
            productionlineApi().batchedit(stateProductionLine.vmModel).then(() => {
                ElMessage.success(ci.proxy.$t('message._system.common.vm.submittip'));
                emit('refresh');
                closeDialog();
            }).catch((error:any) => {
                other.setFormError(ci, error);
            }).finally(() => {
			loadingInstance.close();
		    })
		}
        else{
			loadingInstance.close();
        }
	})
};


// 页面加载时
onMounted(() => {
    
    other.getSelectList('/api/FactoryManagement/ProductionLine/GetFrameworkUsers',[],false).then(x=>{stateProductionLine.AllPrincipalIds = x});
    if (ci.attrs["wtmdata"]) {
		stateProductionLine.vmModel.Ids = ci.attrs["wtmdata"];
	}
	else if (useRouter().currentRoute.value.query.id) {
		stateProductionLine.vmModel.Ids = useRouter().currentRoute.value.query.id as any;
	}

});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh','closeDialog']);
// 关闭弹窗
const closeDialog = () => {
    emit('closeDialog');
};
// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

